-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coerce empty string to null #381
Conversation
@@ -208,6 +208,9 @@ protected function validateType(&$value, $type) | |||
} | |||
|
|||
if ('null' === $type) { | |||
if ($coerce) { | |||
$value = $this->toNull($value); | |||
} | |||
return is_null($value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a newline above return is_null($value);
to make the style checker happy.
@@ -128,7 +128,7 @@ public function getValidCoerceTests() | |||
"boolean":"true", | |||
"object":{}, | |||
"array":[], | |||
"null":null, | |||
"null":"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that you have lots of explicit tests in testValidCoerceCases
, in addition to simply requiring the schema to validate, but that null coercion hasn't been added as one of them. Is there a reason for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. Can you provide an example?
I believe I originally created this file by duplicating BasicTypesTest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh, I think I get what you mean. One sec...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a post-validate test for null.
I also removed what looked like a duplicated block of explicit tests in the same section of code. Not sure if there was any purpose for it...
@@ -211,6 +211,7 @@ protected function validateType(&$value, $type) | |||
if ($coerce) { | |||
$value = $this->toNull($value); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newline is good, but need to remove the unneeded whitespace on this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think we're good - thanks for doing this PR :-). |
Right you are. Closing... |
Fix for the null coercion portion of #379
Coerce empty sting to null for type "null".
@erayd @bighappyface @gtuccini